package com.fh.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fh.mapper.MallProductMapper;
import com.fh.model.Brand;
import com.fh.service.MallProductService;
import com.fh.util.DataTablePageUtil;
import com.fh.vo.MallBrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @create 2020-07-15 21:53
 */
@Service
public class MallProductServiceImpl implements MallProductService {

    @Autowired
    public MallProductMapper mallProductMapper;

    @Override
    public DataTablePageUtil<Brand> selectProduct(DataTablePageUtil<Brand> pageUtil, MallBrandVo vo) {


        //把vo转换成json对象,然后 取出start和length进行合并,传递给mybatis进行条件查询
        JSONObject json= (JSONObject)JSONObject.toJSON(vo);
        json.put("start",pageUtil.getStart());
        json.put("length",pageUtil.getLength());

        List<Brand> list=mallProductMapper.selectBrand(json);

        Integer count = mallProductMapper.queryCount(json);

        pageUtil.setRecordsTotal(count);

        pageUtil.setData(list);

        return pageUtil;
    }

    @Override
    public void addBrand(Brand brand) {
        mallProductMapper.addBrand(brand);
    }

    @Override
    public Brand selectId(Integer brandId) {
        return mallProductMapper.selectId(brandId);
    }

    @Override
    public void updateBrand(Brand brand) {
        mallProductMapper.updateBrand(brand);
    }

    @Override
    public void deleteBrand(Integer brandId) {
        mallProductMapper.deleteBrand(brandId);
    }
}
